package gameObject.effect;

import base.RotatableSprite;
import base.SpriteContainer;

public class BulletEffect extends Effect{
	protected int speed;
	protected int damage;
	protected int targetX;
	protected int targetY;


	public BulletEffect(RotatableSprite sprite,
			int x,int y,int targetX,int targetY,int refX,int refY,
			int dam,int speed,int lifeTime) {
		this.sprite = sprite;
		this.damage = dam;
		this.speed = speed;
		this.lifeTime = lifeTime-1;
		this.targetX = targetX + (targetX-x)*100;;
		this.targetY = targetY + (targetY-y)*100;;
		sprite.defineReferencePixel(refX, refY);
		setPosition(x, y);
		setRotation(arc(targetX-x, targetY-y));
	}

	public boolean isDetroyed()
	{
		return isDetroyed;
	}
	public void update()
	{
		if(lifeTime>0)
		{

			sprite.nextFrame();
			double sp = (double)speed/10;
			moveTo(targetX, targetY, sp);
			lifeTime--;
		}else{
			isDetroyed = true;
		}
		
		
	}
	public void moveTo(int x, int y) {
		double sp = (double)speed/10;
		moveTo(x, y, sp);
	}
	public int hit(SpriteContainer obj){
		if(this.sprite.collidesWith(obj.getSprite(),true))
		{
			return damage;
		}
		return 0;
	}
	public boolean isAir(){
		return false;
	}
}
